﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using App.Data;
using App.CustomEntity;
/// <summary>
/// Summary description for AjaxService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class AjaxService : System.Web.Services.WebService {

    public AjaxService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    /// <summary>
    /// Gets Zones By CityID
    /// </summary>
    /// <param name="cityID"></param>
    /// <returns></returns>
    [WebMethod]
    public List<CustomZone> GetZonesOfCity(int cityID)
    {
        BtcHousingEntities context = new BtcHousingEntities();
        var zones = from P in context.Zones where P.CityID == cityID select new CustomZone { Name = P.Name, ID = P.ID };
        return zones == null ? null : zones.ToList();
    }
    [WebMethod]
    public String GetUnitNameForPropertyType(int propertyTypeID)
    {
        BtcHousingEntities context = new BtcHousingEntities();
        var unit = from P in context.UnitOfPropertyTypes where P.PropertyTypeID == propertyTypeID select P.Unit;
        if (unit != null && unit.Count() > 0)
            return unit.ToList()[0].Name;
        
        return String.Empty;
    }
    [WebMethod]
    public List<App.CustomEntity.BusinessType> GetChildBusinessTypes(int parentBusinessTypeID)
    {
        BtcHousingEntities context = new BtcHousingEntities();
        var types = from P in context.BusinessTypes where P.ParentID == parentBusinessTypeID 
                        select new App.CustomEntity.BusinessType 
                        { 
                            ID=P.ID,
                            LongName = P.LongName,
                            ShortName = P.ShortName
                        };
        return types == null || types.Count() == 0 ? null : types.ToList();
    }
}
